"use strict";

const Controller = require("egg").Controller;

class UserController extends Controller {
  // 用户登录
  async login() {
    const { ctx } = this;
    const body = ctx.request.body;
    const data = await ctx.service.system.user.login(body);
    ctx.body = data;
  }
  // 新增用户
  async addUser() {
    const { ctx } = this;
    const body = ctx.request.body;
    const validateResult = await ctx.validate("system.user", body); // 第一个参数对应于rules目录下目录或文件
    if (!validateResult) {
      return;
    }

    const data = await ctx.service.system.user.addUser(body);
    ctx.body = data;
  }
  //获取用户数据
  async getUserList() {
    const { ctx } = this;
    const query = ctx.request.query;

    console.log("debug log 获取用户数据--> ", query);

    const data = await ctx.service.system.user.getUserList(query);
    ctx.body = data;
  }
  //获取用户数据
  async token() {
    const { ctx } = this;
    const body = ctx.request.body;

    const data = await ctx.service.system.user.token(body);

    ctx.body = data;
  }
  //获取用户数据
  async isToken() {
    const { ctx } = this;
    const body = ctx.request.body;

    const data = await ctx.service.system.user.isToken(body);

    ctx.body = data;
  }
}

module.exports = UserController;
